package com.up4years.utils;

import java.io.UnsupportedEncodingException;
import java.util.ResourceBundle;
import org.apache.commons.lang.StringUtils;
 
/**
 * 公共数据使用

 */
public class CommonUtil {
	private static ResourceBundle resourceBoundle;
	private static final String PAGE_SIZE ="page.size";
	private static final String STATIC_BASE ="resourceUriBase";
	private static final String ALI_AccessKeyID ="ali.AccessKeyID";
	private static final String ALI_AccessKeySecret ="ali.AccessKeySecret";
	private static final String ALI_ENDPOINT ="ali.endpoint";
	private static final String ALI_BucketName ="ali.bucketname";
	private static final String QINIU_ACCESSKEY ="qiniu.accessKey";
	private static final String QINIU_SECRETKEY ="qiniu.secretKey";
	private static final String QINIU_BUCKET ="qiniu.bucket";
	private static final String WEIXIN_APPID ="weixin.APPID";
	private static final String WEIXIN_APPSECRET ="weixin.APPSECRET";
	private static final String WEIXIN_AUTHTOKEN ="weixin.authToken";
	private static final String UCPASS_ACCOUNT_ID ="ucpaas.ACCOUNT_ID";
	private static final String UCPASS_ACCOUNT_TOKEN ="ucpaas.ACCOUNT_TOKEN";
	private static final String UCPASS_APP_ID ="ucpaas.APP_ID";
	private static final String UCPASS_REGISTER_CODE_TEMPLATE_ID ="ucpaas.REGISTER_CODE_TEMPLATE_ID";
	private static final String UCPASS_REGISTER_CODE_TEMPLATE_CONTENT ="ucpaas.REGISTER_CODE_TEMPLATE_CONTENT";
	private static final String UCPASS_REGISTER_CODE_VALID_MINUTE ="ucpaas.REGISTER_CODE_VALID_MINUTE";
	static {
		resourceBoundle = ResourceBundle.getBundle("common");
	}
	/**
	 * 获取common.propertis文件的配置
	 * @param key
	 * @return
	 */
	public static String getCommonValue(String key){
 		String val = resourceBoundle.getString(key);;
		try {
			return new String(val.getBytes("ISO8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
 			e.printStackTrace();
		}
		return null;
	}	
	/**
	 * 获取分页查询默认每页数量
	 * @return
	 */
	public static Integer getDefaultPageSize(){
    	if(StringUtils.isNotBlank(CommonUtil.getCommonValue(PAGE_SIZE))){
			return Integer.parseInt(CommonUtil.getCommonValue(PAGE_SIZE));
		}
		return null;
	}
	/**
	 * 获取静态资源访问路径头
	 * @return
	 */
	public static String getStaticBase(){
		if(StringUtils.isNotBlank(CommonUtil.getCommonValue(STATIC_BASE))){
			return  CommonUtil.getCommonValue(STATIC_BASE);
		}
		return null;
	}
	/**
	 * 获取七牛CDN的AccessKey
	 * @return
	 */
	public static String getQiniuAccessKey(){
		return CommonUtil.getCommonValue(QINIU_ACCESSKEY);
	}
	/**
	 * 获取七牛CDN的SecretKey
	 * @return
	 */
	public static String getQiniuSecretKey(){
		return CommonUtil.getCommonValue(QINIU_SECRETKEY);
	}
	/**
	 * 获取七牛CDN的BUCKET
	 * @return
	 */
	public static String getQINIU_BUCKET(){
		return CommonUtil.getCommonValue(QINIU_BUCKET);
	}
	/**
	 * 获取微信服务号APPID
	 * @return
	 */
	public static String getWEIXIN_APPID(){
		return CommonUtil.getCommonValue(WEIXIN_APPID);
	}
	/**
	 * 获取微信服务号APPSECRET
	 * @return
	 */
	public static String getWEIXIN_APPSECRET(){
		return CommonUtil.getCommonValue(WEIXIN_APPSECRET);
	}
	/**
	 * 获取微信服务号AUTHTOKEN
	 * @return
	 */
	public static String getWEIXIN_AUTHTOKEN(){
		return CommonUtil.getCommonValue(WEIXIN_AUTHTOKEN);
	}
	/**
	 * 获取云之讯ACCOUNT_ID
	 * @return
	 */
	public static String getUCPASS_ACCOUNT_ID(){
		return CommonUtil.getCommonValue(UCPASS_ACCOUNT_ID);
	}
	/**
	 * 获取云之讯CommonConstant
	 * @return
	 */
	public static String getUCPASS_ACCOUNT_TOKEN(){
		return CommonUtil.getCommonValue(UCPASS_ACCOUNT_TOKEN);
	}
	/**
	 * 获取云之讯UCPASS_APP_ID
	 * @return
	 */
	public static String getUCPASS_UCPASS_APP_ID(){
		return CommonUtil.getCommonValue(UCPASS_APP_ID);
	}
	/**
	 * 获取云之讯REGISTER_CODE_TEMPLATE_ID
	 * 短信验证码模版ID
	 * @return
	 */
	public static String getUCPASS_REGISTER_CODE_TEMPLATE_ID(){
		return CommonUtil.getCommonValue(UCPASS_REGISTER_CODE_TEMPLATE_ID);
	}
	/**
	 * 获取云之讯UCPASS_REGISTER_CODE_TEMPLATE_CONTENT
	 * 短信验证码模版
	 * @return
	 */
	public static String getUCPASS_REGISTER_CODE_TEMPLATE_CONTENT(){
		return CommonUtil.getCommonValue(UCPASS_REGISTER_CODE_TEMPLATE_CONTENT);
	}
	/**
	 * 获取云之讯UCPASS_REGISTER_CODE_VALID_MINUTE
	 * 短信验证码有效时间 分钟
	 * @return
	 */
	public static String getUCPASS_REGISTER_CODE_VALID_MINUTE(){
		return CommonUtil.getCommonValue(UCPASS_REGISTER_CODE_VALID_MINUTE);
	}
	/**
	 * 获取阿里云AccessKeyID
	 * @return
	 */
	public static String getALI_AccessKeyID(){
		return CommonUtil.getCommonValue(ALI_AccessKeyID);
	}
	/**
	 * 获取阿里云AccessKeySecret
	 * @return
	 */
	public static String getALI_AccessKeySecret(){
		return CommonUtil.getCommonValue(ALI_AccessKeySecret);
	}
	/**
	 * 获取阿里云数据中心
	 * @return
	 */
	public static String getALI_ENDPOINT(){
		return CommonUtil.getCommonValue(ALI_ENDPOINT);
	}
	/**
	 * 获取阿里云数据中心bucket
	 * @return
	 */
	public static String getALI_BucketName(){
		return CommonUtil.getCommonValue(ALI_BucketName);
	}
}